//
//  myLoadingViewController.m
//  iNews
//
//  Created by lanou3g on 14-12-15.
//  Copyright (c) 2014年 张在青. All rights reserved.
//

#import "myLoadingViewController.h"
#import "myLoadinView.h"
#import "radioViewController.h"
#import "videoViewController.h"
#import "videoView.h"
#import "radioView.h"
@interface myLoadingViewController ()
@property(nonatomic,retain)myLoadinView *myLoad;
@end


@implementation myLoadingViewController

- (void)dealloc
{
    [_myLoad release];
    [_radio release];
    [_video release];
    [super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
        self.myLoad = [[[myLoadinView alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease];
            self.title = @"我的下载";
    }
    return self;
}

-(void)loadView{

    self.view = self.myLoad;

}
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    
    UIBarButtonItem *right = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style: UIBarButtonItemStyleDone target:self action:@selector(edtionAction)];
    
    self.navigationItem.rightBarButtonItem = right;
    
    //添加子控制器
    self.video = [[[videoViewController alloc] init]autorelease];
    
    [self addChildViewController:self.video];
    
    [self.myLoad addSubview:self.video.view];
    
    self.radio = [[[radioViewController alloc] init] autorelease];
    
    [self addChildViewController:self.radio];
    [self.myLoad addSubview:self.radio.view];
    
    //给segment 添加方法
    [self.myLoad.segment addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];
    // Do any additional setup after loading the view.
}

//segment事件
-(void)segAction:(UISegmentedControl *)sender{
    
    
    if (sender.selectedSegmentIndex == 0) {
        [self.myLoad bringSubviewToFront:self.radio.view];
    }else{
        
        [self.myLoad bringSubviewToFront:self.video.view];
    }
    
    
}

// 编辑事件

-(void)edtionAction{

    //点击删除按钮时给删除状态
    _style = UITableViewCellEditingStyleDelete;
    
     self.radio.styl =_style;
    self.video.vstyle = _style;
    BOOL flag =  self.video.vid.videoTab.editing;
    
    if (flag) {
        self.navigationItem.rightBarButtonItem.title = @"编辑";
    }else{
            
        self.navigationItem.rightBarButtonItem.title = @"完成";
        }
    
    [self.video.vid.videoTab setEditing:!flag animated:YES];
    
    [self.radio.rad.radioTab setEditing:!flag animated:YES];
    
        
    

}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
